<template>
	<view>
		<view class="status_bar"></view>
		<view class="top">
			<u-gap height="60"></u-gap>
			<view class="topbar padding-lr-xl flex-row justify-between align-center">
				<view v-if="!token" class="flex-row align-center" @click="$goto('/pages/login/login')">
					<u-avatar text="登录" bg-color="gray"></u-avatar>
					<view class="name margin-left">点击登录</view>
				</view>

				<view v-if="token" class="flex-row align-center" @click="$goto('/pages/user/index')">
					<u-avatar :src="userinfo.full_portrait"></u-avatar>
					<view class="name margin-left u-line-1">{{userinfo.nickname}}</view>
				</view>

				<view class="icons">
					<image class="icon margin-right" src="../../static/images/mine-3.png" @click="$goto('/pages/msg/index')"></image>
					<image class="icon" src="../../static/images/mine-2.png" @click="$goto('/pages/mine/setting')"></image>
				</view>
			</view>
			<u-gap height="60"></u-gap>
			<view class="padding-lr-xl">
				<view class="topdata flex-row justify-around">
					<view class="item flex-col align-center" @click="$goto('/pages/mine/yue')">
						<view class="number">{{finance.balance?finance.balance:0}}</view>
						<view class="text">余额</view>
					</view>
					<view class="item flex-col align-center" @click="$goto('/pages/mine/jifen')">
						<view class="number">{{finance.score?finance.score:0}}</view>
						<view class="text">积分</view>
					</view>
					<view class="item flex-col align-center" @click="$goto('/pages/mine/jixiao')">
						<view class="number">{{finance.performance?finance.performance:0}}</view>
						<view class="text">绩效</view>
					</view>
				</view>
			</view>
		</view>

		<view class="projects padding-lg">
			<view class="bg-white padding border-radius">
				<view class="flex-row justify-between">
					<view class="title">最近项目</view>
					<view class="more" @click="$goto('/pages/order/list')">查看全部订单<u-icon size="20" name="arrow-right"></u-icon>
					</view>
				</view>

				<view class="main flex-row justify-between align-center margin-top-xs" @click="$goto('/pages/order/detail?no=' + order.trade_no)"
				 v-show="order">
					<u-avatar :src="order.product_pic" mode="square" size="140"></u-avatar>
					<view class="right">
						<view class="u-line-1 text-bold text-lg" style="color: #333;">{{order.product_name}}</view>
						<view class="u-line-1 margin-tb-xs ">{{order?order.merchant.merchant_name:''}}</view>
						<view class="u-line-1 flex-row align-center justify-between">
							<view>当前状态：<text class="text-primary">{{order.status_text}}</text></view>
							<view class="text-primary">{{order.total_price<0?'':'￥'+order.total_price}}</view>
						</view>
					</view>
				</view>

				<view class="btns flex-row justify-between align-center margin-top-xl" v-show="order">
					<view class="btn red" v-if="order.status == -1 && order.can_pay == 1" @click.stop="$goto('/pages/order/create?no=' + order.trade_no)">填写订单</view>
					<view class="btn red" v-if="order.status == -1 && order.can_pay > 1" @click.stop="$goto('/pages/order/pay?no=' + order.trade_no)">去付款</view>
					<view class="btn red" v-if="order.status>3 && order.paid_status==0" @click.stop="$goto('/pages/order/pay?no=' + order.trade_no + '&rest=1')">付尾款</view>
					<view class="btn red" v-if="order.status == 7" @click.stop="$goto('/pages/comment/submit?no='+order.trade_no)">去评价</view>
					<view class="btn" v-if="order.status == -1" @click.stop="cancelModal=true">取消订单</view>
				</view>

				<my-nodata type="3" size="sm" text="暂 无 订 单" v-show="!order"></my-nodata>

				<!-- 取消订单 -->
				<u-modal v-model="cancelModal" content="确定取消该订单？" show-cancel-button @confirm="cancelOrder" @cancel="cancelModal=false"></u-modal>
			</view>
		</view>

		<view class="service padding-lr-lg">
			<view class="bg-white padding border-radius">
				<view class="more">更多服务</view>
				<u-grid :col="4" :border="false" class="margin-top-xs">
					<u-grid-item v-for="i in service" :key="i.id" @click="$goto(i.url)">
						<image :src="i.icon" mode="widthFix" style="width: 60rpx;height: 60rpx;"></image>
						<view class="grid-text margin-top-sm">{{i.text}}</view>
					</u-grid-item>
				</u-grid>
			</view>
		</view>
		<u-gap height="32"></u-gap>
	</view>
</template>

<script>
	import store from '@/store.js'
	export default {
		data() {
			return {
				no: '',
				cancelModal: false,
				service: [{
						id: 1,
						text: '优惠劵',
						icon: '../../static/images/mine-s1.png',
						url: '/pages/mine/coupons'
					}, {
						id: 2,
						text: '分享有礼',
						icon: '../../static/images/mine-s2.png',
						url: '/pages/mine/share'
					}, {
						id: 3,
						text: '账户安全',
						icon: '../../static/images/mine-s3.png',
						url: '/pages/login/safe'
					}, {
						id: 9,
						text: '我的评价',
						icon: '../../static/images/mine-s9.png',
						url: '/pages/comment/list'
					}, {
						id: 4,
						text: '客服',
						icon: '../../static/images/mine-s4.png',
						url: '/pages/other/kefu'
					}, {
						id: 5,
						text: '我的会员',
						icon: '../../static/images/mine-s5.png',
						url: '/pages/mine/level'
					}, {
						id: 6,
						text: '我的收藏',
						icon: '../../static/images/mine-s6.png',
						url: '/pages/mine/follow'
					},
					{
						id: 7,
						text: '我的发票',
						icon: '../../static/images/mine-s7.png',
						url: '/pages/order/fapiao'
					},
					{
						id: 8,
						text: '关于',
						icon: '../../static/images/mine-s8.png',
						url: '/pages/other/about'
					},
					// #ifdef H5
					{
						id: 10,
						text: '发布需求',
						icon: '../../static/images/mine-s8.png',
						url: '/pages/demand/release'
					},
					{
						id: 99,
						text: '调试',
						icon: '../../static/images/mine-s8.png',
						url: '/pages/other/test'
					}
					// #endif
				],
				order: ''
			};
		},
		computed: {
			finance: state => store.state.finance,
			userinfo: state => store.state.userinfo,
			token: state => store.state.token
		},
		onShow() {
			this.getUser();
			this.getOrder();
		},
		onPullDownRefresh() {
			this.getUser();
			this.getOrder();
		},
		methods: {
			getUser() {
				this.$u.api.getUserinfo();
			},
			getOrder() {
				this.$u.get('/order/member/order').then(res => {
					this.order = res.data.result.order || ''
					this.no = this.order.trade_no || ''
					uni.stopPullDownRefresh();
				})
			},
			cancelOrder() {
				uni.showLoading({
					title: '取消中...',
					mask: true
				})
				this.$u.get('/order/cancel?trade_no=' + this.no).then(res => {
					this.$msg(res.data.msg, 1000, true)
					this.getOrder()
				})
			}
		}
	}
</script>

<style lang="scss">
	.status_bar {
		background: url(../../static/images/mine-bg.png);
		background-size: 100% auto;
		position: fixed;
		z-index: 999;
	}

	.top {
		background: url(../../static/images/mine-bg.png);
		background-size: cover;
		width: 750rpx;
		height: 468rpx;
		padding-top: var(--status-bar-height);
	}

	.topbar {
		width: 100%;
		height: 100rpx;

		.name {
			font-size: 32rpx;
			width: 400rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: rgba(255, 255, 255, 1);
		}

		.icons {
			height: 40rpx;

			.icon {
				width: 40rpx;
				height: 40rpx;
			}
		}
	}

	.topdata {
		.item {
			width: 33.333%;
		}

		.number {
			font-size: 32rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: rgba(255, 255, 255, 1);
		}

		.text {
			margin-top: 16rpx;
			font-size: 24rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: rgba(153, 153, 153, 1);
		}
	}

	.projects {
		margin-top: -110rpx;

		.title {
			font-size: 28rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: rgba(51, 51, 51, 1);
			margin-bottom: 40rpx;
		}

		.right {
			width: 450rpx;
		}

		.btns {
			.btn {
				width: 280rpx;
				height: 56rpx;
				border-radius: 8rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				border: 1px solid rgba(172, 172, 172, 1);
				color: #bdbdbd;

				&.red {
					border: 1px solid rgba(147, 107, 41, 1);
					color: #936B29;
				}
			}
		}
	}

	.service {
		.more {
			font-size: 28rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: rgba(51, 51, 51, 1);
		}

		.grid-text {
			font-size: 22rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: rgba(51, 51, 51, 1);
		}
	}

	.projects {

		.more {
			font-size: 22rpx;
			color: #999999;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: rgba(153, 153, 153, 1);
		}
	}
</style>
